#!/bin/bash

#Created by turk 2017-08-03
#Version 1.0 


if [ $# -lt 1 ]; then
	echo `date +"%Y-%m-%d %H:%M:%S"`  "Usage:<DATE>"
	exit 1
fi

DATE=$1
WORKPATH=/home/hadoop/work
DATAPATH=/home/hadoop/data

LOGFILE=${WORKPATH}/log/hnc_data_refresh.log


echo `date +"%Y-%m-%d %H:%M:%S"`  "-----------------------------" | tee -a $LOGFILE
echo `date +"%Y-%m-%d %H:%M:%S"`  "Shell Version 1.0 (2017-08-03)"     | tee -a $LOGFILE
echo `date +"%Y-%m-%d %H:%M:%S"`  "HNC Data Refresh"  | tee -a $LOGFILE
echo `date +"%Y-%m-%d %H:%M:%S"`  "-----------------------------"  | tee -a $LOGFILE
echo `date +"%Y-%m-%d %H:%M:%S"`  "Start..."  | tee -a $LOGFILE


hive -e "insert overwrite local directory '/home/hadoop/data/hnc_http_$DATE'
	row format delimited
	fields terminated by '|'
	select * from ods_udii_http where dt = $DATE AND destinationip in (2032399715);"
	
hive -e "insert overwrite local directory '/home/hadoop/data/hnc_nohttp_$DATE'
	row format delimited
	fields terminated by '|'
	select * from ods_udii_nohttp where dt = $DATE AND destinationip in (2032399715);"	

mv /home/hadoop/data/hnc_http_$DATE /home/hadoop/data/hncdata/http
mv /home/hadoop/data/hnc_nohttp_$DATE /home/hadoop/data/hncdata/nohttp

echo `date +"%Y-%m-%d %H:%M:%S"`      "Quit" | tee -a $LOGFILE

exit 0
